package com.dd.stack.es.pojo.req;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dd.stack.common.util.param.PageParams;
import com.dd.stack.es.pojo.DO.ExcelProductDO;
import com.dd.stack.es.pojo.params.ProductQueryParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/5/11 16:22
 * @Description 产品分页请求类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("产品分页请求类")
public class ProductPageReq {
    @ApiModelProperty("分页请求参数")
    private PageParams pageParams;
    @ApiModelProperty("产品查询请求参数")
    private ProductQueryParams productQueryParams;

    // 构建查询条件
    public LambdaQueryWrapper<ExcelProductDO> buildLambdaQueryWrapper() {
        LambdaQueryWrapper<ExcelProductDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        // DO查询参数
        if (productQueryParams != null) {
            if (productQueryParams.getMinPrice()!= null) {
                lambdaQueryWrapper.ge(ExcelProductDO::getPrice, productQueryParams.getMinPrice());
            }
            if (productQueryParams.getMaxPrice()!= null) {
                lambdaQueryWrapper.le(ExcelProductDO::getPrice, productQueryParams.getMaxPrice());
            }
            if (productQueryParams.getMinStock()!= null) {
                lambdaQueryWrapper.ge(ExcelProductDO::getStock, productQueryParams.getMinStock());
            }
            if (productQueryParams.getMaxStock()!= null) {
                lambdaQueryWrapper.le(ExcelProductDO::getStock, productQueryParams.getMaxStock());
            }
            if (productQueryParams.getProductName()!= null) {
                lambdaQueryWrapper.like(ExcelProductDO::getProductName, productQueryParams.getProductName());
            }
            if (productQueryParams.getEarliestCreateTime()!= null) {
                lambdaQueryWrapper.ge(ExcelProductDO::getCreateTime, productQueryParams.getEarliestCreateTime());
            }
            if (productQueryParams.getLatestCreateTime()!= null) {
                lambdaQueryWrapper.le(ExcelProductDO::getCreateTime, productQueryParams.getLatestCreateTime());
            }
        }
        return lambdaQueryWrapper;
    }
}

